package com.woniu.model;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 标准响应结果类
 * @param <T>
 */
public class Result<T> {
    private String message;
    private Integer code;
    private T data;

    public Result() {
    }

    public Result(String message, Integer code, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public static <S> Result<S> newInstance(Class<S> type){
        Result<S> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }

    public static <S> Result<List<S>> newListInstance(Class<S> type){
        Result<List<S>> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }

    public static <S> Result<Set<S>> newSetInstance(Class<S> type){
        Result<Set<S>> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }
    public static <S> Result<Page<S>> newPageInstance(Class<S> type){
        Result<Page<S>> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }

    public static <S> Result<Page<Map<S,S>>> newPageMapInstance(Class<S> type){
        Result<Page<Map<S,S>>> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }

    public static <S> Result<List<Map<S,S>>> newListMapInstance(Class<S> type){
        Result<List<Map<S,S>>> result = new Result<>();
        result.setCode(200);
        result.setMessage("访问成功");
        return result;
    }
    /**
     * 获取
     * @return message
     */
    public String getMessage() {
        return message;
    }

    /**
     * 设置
     * @param message
     */
    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    /**
     * 获取
     * @return code
     */
    public Integer getCode() {
        return code;
    }

    /**
     * 设置
     * @param code
     */
    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    /**
     * 获取
     * @return data
     */
    public T getData() {
        return data;
    }

    /**
     * 设置
     * @param data
     */
    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public String toString() {
        return "Result{message = " + message + ", code = " + code + ", data = " + data + "}";
    }
}
